#pragma once

#include <cinatra.hpp>

#include "cinatra/websocket.hpp"

#include "singleton.hpp"

#include <set>
#include <unordered_map>

using namespace cinatra;

namespace bz {

	struct room_conn {
		std::set<coro_http_connection*> conn_set_;
	};

	class ws_manage {
	public:
		sigletonclass(ws_manage);

	public:

		void on_open(coro_http_connection* conn);
		void on_close(coro_http_connection* conn);

		void broad_meet_msg(int &meet_id,std::string msg);
		void broad_msg(const std::string msg);
		async_simple::coro::Lazy<void> on_message(coro_http_connection* conn ,std::string_view &data);

		async_simple::coro::Lazy<void> write_msg(coro_http_connection* conn,std::string msg);
		//std::set<coro_http_connection*> ws_client_set_;
	private:

		std::unordered_map<int, room_conn*> romm_ws_map_;
		std::set<coro_http_connection*> all_client_set_;
		ws_manage();

	};

	class ws_server {

	public:
		async_simple::coro::Lazy<void> hand(coro_http_request& req, coro_http_response& resp);

	};
}


